package org.dei.perla.sys.registry;

import java.util.ArrayList;

import org.dei.perla.parser.expressions.*;
import org.dei.perla.parser.statements.*;
import org.dei.perla.sys.device.fpc.FunctionalityProxyComponent;
import org.dei.perla.test.llqruntime.simulator.FPCmockup;


/**
 * MOCKUP DEL REGISTRY
 * @author diego
 */
public class Registry {
	
	private static ArrayList<FunctionalityProxyComponent> pActiveFPCs = new ArrayList<FunctionalityProxyComponent>();
	
	public static ArrayList<FunctionalityProxyComponent> askRegistryForFPCs(LLStatement parStatement) {
		ArrayList<FunctionalityProxyComponent> tArrayToReturn = new ArrayList<FunctionalityProxyComponent>();
		Node tClause = parStatement.getExecuteIfClause().getCondition();
		if (tClause instanceof NodeExistsAttribute) 
			{
			
			String tAttrName = ((NodeExistsAttribute) tClause).getExistsAttribute().getLogicalObjectAttributeName();			
			for (FunctionalityProxyComponent tFPC : pActiveFPCs) {
				
				for (NodeLogicalObjectAttribute tNode : tFPC.getAttributeList()) {
					
					if (tNode.getLogicalObjectAttributeName().equals(tAttrName)) {
						tFPC.registerQuery(parStatement);
						tArrayToReturn.add((FPCmockup)tFPC);
					}
				}
				
				
			}
			
			}
		return tArrayToReturn;
	}
	
	public static void registerThisFPC(FunctionalityProxyComponent parFPC) {
		pActiveFPCs.add(parFPC);
	}
}
